package cn.itcast.mq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.retry.MessageRecoverer;
import org.springframework.amqp.rabbit.retry.RepublishMessageRecoverer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FailMessage {
    @Bean
    public DirectExchange directExchange2(){
        return new DirectExchange("fail.exchange");
    }
    @Bean
    public Queue failMessageQueue(){
        return new Queue("fail.queue");
    }
    @Bean(name = "binding2")
    public Binding binding(DirectExchange directExchange2,Queue failMessageQueue){
       return BindingBuilder.bind(failMessageQueue).to(directExchange2).with("failKey");
    }

    @Bean
    //重新dinginess了处理失败信息的类 覆盖原有的类？？？？？？有点没理解
    public RepublishMessageRecoverer republishMessageRecoverer(RabbitTemplate rabbitTemplate){
        return new RepublishMessageRecoverer(rabbitTemplate,"fail.exchange","failKey");
    }

}
